(function() {
    'use strict';

    /**
     * @ngdoc directive
     * @name webApp.directive:pager
     * @description
     * # pager 
     */
    angular.module('webApp')
        .directive('colorStyleChoice', function() {
            return {
                restrict: "E",
                // require: 'ngModel',
                template: "<div ng-init='initData()'><div ng-repeat='stylecolor in styleColors' style='display:inline-block;'> <div ><button style='background-color:{{stylecolor.zujian_backColor}};height:30px;width:30px;margin:7px;'  ng-click='clickStyle(stylecolor,$index)'></button></div></div><div style='text-align:center;line-height:2em;'>点击后保存，小程序下拉刷新看效果；也可以自定义颜色↓</div></div>",
                scope: {
                    callback: "&",
                    ngModel: "="
                },
                controller: ['$templateCache', '$rootScope', '$scope', '$compile', 'dataService', '$timeout', function($templateCache, $rootScope, $scope, $compile, dataService, $timeout) {
                    var styleColors = [{
                        zujian_backColor: '#fe7b05',
                        detail_cartBtnColor: '#fff6f1',
                        time_backColor: '#ffffff',
                        page_titleColor: '#4e4e4e',
                        describe_fontColor: '#a0a0a0',
                        zujian_backFontColor: '#ffffff',
                        zujian_fenge: 'https://img.alicdn.com/imgextra/i4/20841398/O1CN011MCK9jxZRqUY54Y_!!20841398.png',
                        home_img: 'https://img.alicdn.com/imgextra/i3/20841398/O1CN011MCK9q5ENHMVXTE_!!20841398.jpg',
                        detail_img: 'https://img.alicdn.com/imgextra/i1/20841398/O1CN011MCK9xgSdwpG3Zf_!!20841398.jpg',
                        name: '青草深绿系'
                    }, {
                        zujian_backColor: '#f280b1',
                        detail_cartBtnColor: '#ffeef6',
                        time_backColor: '#ffffff',
                        page_titleColor: '#4e4e4e',
                        describe_fontColor: '#a0a0a0',
                        zujian_backFontColor: '#ffffff',
                        zujian_fenge: 'https://img.alicdn.com/imgextra/i4/20841398/O1CN011MCK9jxZRqUY54Y_!!20841398.png',
                        home_img: 'https://img.alicdn.com/imgextra/i4/20841398/O1CN011MCK9xTBuOkUkxU_!!20841398.jpg',
                        detail_img: 'https://img.alicdn.com/imgextra/i1/20841398/O1CN011MCK9wMd9AC19zU_!!20841398.jpg',
                        name: '粉色系'
                    }, {
                        zujian_backColor: '#fc583d',
                        detail_cartBtnColor: '#ffeef6',
                        time_backColor: '#ffffff',
                        page_titleColor: '#4e4e4e',
                        describe_fontColor: '#a0a0a0',
                        zujian_backFontColor: '#ffffff',
                        zujian_fenge: 'https://img.alicdn.com/imgextra/i4/20841398/O1CN011MCK9jxZRqUY54Y_!!20841398.png',
                        home_img: 'https://img.alicdn.com/imgextra/i4/20841398/O1CN011MCK9wizvtBBzlI_!!20841398.jpg',
                        detail_img: 'https://img.alicdn.com/imgextra/i4/20841398/O1CN011MCK9vckhxOjrBt_!!20841398.jpg',
                        name: '口红系'
                    }, {
                        zujian_backColor: '#b05ae1',
                        detail_cartBtnColor: '#f9f1ff',
                        time_backColor: '#ffffff',
                        page_titleColor: '#4e4e4e',
                        describe_fontColor: '#a0a0a0',
                        zujian_backFontColor: '#ffffff',
                        zujian_fenge: 'https://img.alicdn.com/imgextra/i4/20841398/O1CN011MCK9jxZRqUY54Y_!!20841398.png',
                        home_img: 'https://img.alicdn.com/imgextra/i4/20841398/O1CN011MCK9wiy3ZRkJYT_!!20841398.jpg',
                        detail_img: 'https://img.alicdn.com/imgextra/i4/20841398/O1CN011MCK9wg4k2GN5ws_!!20841398.jpg',
                        name: '紫色系'
                    }, {
                        zujian_backColor: '#6759e0',
                        detail_cartBtnColor: '#efecff',
                        time_backColor: '#ffffff',
                        page_titleColor: '#4e4e4e',
                        describe_fontColor: '#a0a0a0',
                        zujian_backFontColor: '#ffffff',
                        zujian_fenge: 'https://img.alicdn.com/imgextra/i4/20841398/O1CN011MCK9jxZRqUY54Y_!!20841398.png',
                        home_img: 'https://img.alicdn.com/imgextra/i1/20841398/O1CN011MCK9wsuYsXht2x_!!20841398.jpg',
                        detail_img: 'https://img.alicdn.com/imgextra/i1/20841398/O1CN011MCK9q5FW8m4crE_!!20841398.jpg',
                        name: '紫兰色系'
                    }, {
                        zujian_backColor: '#40a9eb',
                        detail_cartBtnColor: '#ecf9ff',
                        time_backColor: '#ffffff',
                        page_titleColor: '#4e4e4e',
                        describe_fontColor: '#a0a0a0',
                        zujian_backFontColor: '#ffffff',
                        zujian_fenge: 'https://img.alicdn.com/imgextra/i4/20841398/O1CN011MCK9jxZRqUY54Y_!!20841398.png',
                        home_img: 'https://img.alicdn.com/imgextra/i3/20841398/O1CN011MCK9uOHG31rL9k_!!20841398.jpg',
                        detail_img: 'https://img.alicdn.com/imgextra/i4/20841398/O1CN011MCK9uOI48AKfok_!!20841398.jpg',
                        name: '蓝1系'
                    }, {
                        zujian_backColor: '#3ec9cc',
                        detail_cartBtnColor: '#f3ffff',
                        time_backColor: '#ffffff',
                        page_titleColor: '#4e4e4e',
                        describe_fontColor: '#a0a0a0',
                        zujian_backFontColor: '#ffffff',
                        zujian_fenge: 'https://img.alicdn.com/imgextra/i4/20841398/O1CN011MCK9jxZRqUY54Y_!!20841398.png',
                        home_img: 'https://img.alicdn.com/imgextra/i3/20841398/O1CN011MCK9vuNOE83nny_!!20841398.jpg',
                        detail_img: 'https://img.alicdn.com/imgextra/i3/20841398/O1CN011MCK9w6oZBbJwyy_!!20841398.jpg',
                        name: '绿1系'
                    }, {
                        zujian_backColor: '#1fbc91',
                        detail_cartBtnColor: '#f0fffa',
                        time_backColor: '#ffffff',
                        page_titleColor: '#4e4e4e',
                        describe_fontColor: '#a0a0a0',
                        zujian_backFontColor: '#ffffff',
                        zujian_fenge: 'https://img.alicdn.com/imgextra/i4/20841398/O1CN011MCK9jxZRqUY54Y_!!20841398.png',
                        home_img: 'https://img.alicdn.com/imgextra/i1/20841398/O1CN011MCK9xJ3K3Ij2x0_!!20841398.jpg',
                        detail_img: 'https://img.alicdn.com/imgextra/i1/20841398/O1CN011MCK9wMcTdLrfSS_!!20841398.jpg',
                        name: '绿2系'
                    }, {
                        zujian_backColor: '#c1e047',
                        detail_cartBtnColor: '#fcfef0',
                        time_backColor: '#ffffff',
                        page_titleColor: '#4e4e4e',
                        describe_fontColor: '#a0a0a0',
                        zujian_backFontColor: '#ffffff',
                        zujian_fenge: 'https://img.alicdn.com/imgextra/i4/20841398/O1CN011MCK9jxZRqUY54Y_!!20841398.png',
                        home_img: 'https://img.alicdn.com/imgextra/i1/20841398/O1CN011MCK9wUZkbcuRwW_!!20841398.jpg',
                        detail_img: 'https://img.alicdn.com/imgextra/i3/20841398/O1CN011MCK9vuOSv9yXLv_!!20841398.jpg',
                        name: '绿黄系'
                    }, {
                        zujian_backColor: '#7e6b5a',
                        detail_cartBtnColor: '#f6f1ed',
                        time_backColor: '#ffffff',
                        page_titleColor: '#4e4e4e',
                        describe_fontColor: '#a0a0a0',
                        zujian_backFontColor: '#ffffff',
                        zujian_fenge: 'https://img.alicdn.com/imgextra/i4/20841398/O1CN011MCK9jxZRqUY54Y_!!20841398.png',
                        home_img: 'https://img.alicdn.com/imgextra/i2/20841398/O1CN011MCK9wEnkpxXmrw_!!20841398.jpg',
                        detail_img: 'https://img.alicdn.com/imgextra/i1/20841398/O1CN011MCK9q5Hayaohiw_!!20841398.jpg',
                        name: '棕系'
                    }, {
                        zujian_backColor: '#b68952',
                        detail_cartBtnColor: '#fff5eb',
                        time_backColor: '#ffffff',
                        page_titleColor: '#4e4e4e',
                        describe_fontColor: '#a0a0a0',
                        zujian_backFontColor: '#ffffff',
                        zujian_fenge: 'https://img.alicdn.com/imgextra/i4/20841398/O1CN011MCK9jxZRqUY54Y_!!20841398.png',
                        home_img: 'https://img.alicdn.com/imgextra/i2/20841398/O1CN011MCK9xJ3BlDNOj4_!!20841398.jpg',
                        detail_img: 'https://img.alicdn.com/imgextra/i2/20841398/O1CN011MCK9w6pAcIdsRu_!!20841398.jpg',
                        name: '浅棕系'
                    }, {
                        zujian_backColor: '#34495e',
                        detail_cartBtnColor: '#f1f8ff',
                        time_backColor: '#ffffff',
                        page_titleColor: '#4e4e4e',
                        describe_fontColor: '#a0a0a0',
                        zujian_backFontColor: '#ffffff',
                        zujian_fenge: 'https://img.alicdn.com/imgextra/i4/20841398/O1CN011MCK9jxZRqUY54Y_!!20841398.png',
                        home_img: 'https://img.alicdn.com/imgextra/i3/20841398/O1CN011MCK9vuN7bwMX5G_!!20841398.jpg',
                        detail_img: 'https://img.alicdn.com/imgextra/i4/20841398/O1CN011MCK9ujL1c8PLwJ_!!20841398.jpg',
                        name: '深色系'
                    }]

                    $scope.bClass = "{'red':true,'green':false}";
                    $scope.initData = function() {
                        $scope.styleColors = styleColors;
                        // var styleColorChoice = _.findWhere($scope.ngModel, {
                        //     name: 'colorstylechoice'
                        // });
                        // var currentStyleColor = styleColors[Number(styleColorChoice.value)];
                        // _.map($scope.ngModel, function(zujianObj, index) {
                        //     if (zujianObj.name && currentStyleColor[zujianObj.name]) {
                        //         $scope.ngModel[index].value = currentStyleColor[zujianObj.name];
                        //     }
                        // });
                    }
                    $scope.chosedClass =function(stylecolor){
                            
                    }
                    $scope.clickStyle = function(stylecolor, color_index) {
                        console.error("stylecolor",stylecolor);
                        _.map($scope.ngModel, function(zujianObj, index) {
                            if (zujianObj.name && stylecolor[zujianObj.name]) {
                                $scope.ngModel[index].value = stylecolor[zujianObj.name];
                            } else if (zujianObj.name == 'colorstylechoice') {
                                $scope.ngModel[index].value = color_index;
                            }
                        });
                        if($scope.callback){
                            $scope.callback();
                        }
                    }
                }],
                link: function(scope, element, attrs, ueditor) {}
            }
        });
})();